package com.zzc.controller;

import com.select.pojo.Achievement;
import com.select.pojo.Courses;
import com.select.pojo.Teacher;
import com.zzc.service.CoursesService;
import com.zzc.service.LoginService;
import com.zzc.service.StudentService;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin
@Controller
public class CoursesController {
    @Autowired
    CoursesService coursesService;
    Courses courses=new Courses();
    @GetMapping("/findAll")
    @ResponseBody
    public List<Courses> findOne(@RequestParam String teaAccount){

        List<Courses> list=coursesService.findAll(teaAccount);
        return list;
    }
    @GetMapping("/findone")
    @ResponseBody
    public Courses findOne1(@RequestParam String couId){

        courses=coursesService.findone(couId);
        return courses;
    }
    @GetMapping("/edit")
    @ResponseBody
    public Integer findOne2(@RequestParam("couTime") String couTime,
                        @RequestParam("couWeek") String couWeek,
                        @RequestParam("crPlace") String crPlace,
                        @RequestParam("couIntroduce") String couIntroduce,
                        @RequestParam("couId") String couId){

            Integer i =coursesService.edit(couTime,couWeek,crPlace,couIntroduce,couId);
            return  i;

    }
    @Autowired
    StudentService studentService;
    @GetMapping("/add")
    @ResponseBody
    public Integer add(@RequestParam String achId, @RequestParam double achNum,
                   @RequestParam String teaAccount,@RequestParam String couId ,
                   @RequestParam String stuAccount,
                   @RequestParam  String semester,@RequestParam double achEnd,
                   @RequestParam double achDay,@RequestParam double achEndProportion,
                   @RequestParam double achDayProportion){
        Integer i=studentService.add(achId,achNum,
                teaAccount,couId,stuAccount,semester,
                achEnd,achDay,achEndProportion,achDayProportion);
        return  i;
    }
    @GetMapping("/sel")
    @ResponseBody
    public Achievement findStu(@RequestParam String stuAccount,
                               @RequestParam String couId) {
        return  studentService.findstuone(stuAccount,couId);
    }
    @GetMapping("/sel1")
    @ResponseBody
    public Achievement findStu1(@RequestParam String stuAccount) {
        return  studentService.findone1(stuAccount);
    }
    @Autowired
    LoginService loginService;
    @GetMapping("/selTea")
    @ResponseBody
    public Teacher findTea(@RequestParam String teaAccount){
        return loginService.findOneTea(teaAccount);
    }
    @GetMapping("/up")
    @ResponseBody
    public Integer up(@RequestParam String teaLev ,@RequestParam String teaAccount ){
        Integer i=loginService.up(teaLev,teaAccount);
        return i;
    }

    @GetMapping("/upda")
    @ResponseBody
    public Integer upda(@RequestParam String achEnd,
                        @RequestParam String achDay,
                        @RequestParam String achNum,
                        @RequestParam String stuAccount){
        Integer i =studentService.upda(achEnd,achDay,achNum,stuAccount);
        return i;
    }
}
